package com.nanyang.tms.controller.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class ContextInterceptor  extends HandlerInterceptorAdapter{

	  @Override
	  public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler){
		 if(!StringUtils.isEmpty(request.getHeader("pin"))){
			 request.setAttribute("pin",request.getHeader("pin"));
		 }
		 else{
			 request.setAttribute("pin","admin");
		 }
		 if(!StringUtils.isEmpty(request.getHeader("companyCode"))){
			 request.setAttribute("companyCode",request.getHeader("companyCode"));
		 }
		 else{
			 request.setAttribute("companyCode","S22112922560648075");
		 }
		 if(!StringUtils.isEmpty(request.getHeader("ip"))){
			 request.setAttribute("ip",request.getHeader("ip"));
		 }
		 else{
			 request.setAttribute("ip","127.0.0.1");
		 }
		 
		 if(!StringUtils.isEmpty(request.getHeader("employeeNo"))){
			 request.setAttribute("employeeNo",request.getHeader("employeeNo"));
		 }
		 else{
			 request.setAttribute("employeeNo","1111");
		 }
		 if(!StringUtils.isEmpty( request.getHeader("deptCode"))){
			 request.setAttribute("deptCode",request.getHeader("deptCode"));
		 }
		 else{
			 request.setAttribute("deptCode","1111");
		 }
		  return true;
	  }
}
